<?php
require_once(dirname(__FILE__)."/soap_chain_with_characteristics.class.php");
//global_config::get_instance()->add_server_class("SoapChainOfValueChar","soap_chain");
global_config::get_instance()->add_server_class("SoapChainOfValueString","soap_chain");
global_config::get_instance()->add_server_class("SoapChainOfChains","soap_chain");

class soap_chain extends soap_chain_with_characteristics
{
	/**
	 * Uniforn Chains
	 *
	 * @var soap_array_of_uniform_chain_base
	 */
	public $UniformChains = array();

	
     function __construct() {
     	parent::__construct();
     }
     
     
     /**
	 * Save to db
	 *
	 *
	 *
	 */
	public function save_to_db() 
	{
        $parent_id  = parent::save_to_db('Chain');
        $this->UniformChains->save_to_db($parent_id);
		return $parent_id;
	}

	/**
	 * Load from db
	 *
	 *
	 *
	 */
	public function load_from_db($chain_id) {
		parent::load_from_db($chain_id);
		
		$chain = new chain();
		$dba = db_adapter::get_instance();
		$criteria = new query_criteria();

		$criteria->add_criterion($chain->parent_id,criterion_type::$equal,$chain_id);
		$criteria->add_criterion($chain->chain_type,criterion_type::$equal,'uniformchain');

		$chain_list = $dba->get_list($chain,$criteria);

		if (is_a($this->Alphabet, 'soap_alphabet_value_char'))
		{
			$this->UniformChains = new soap_array_of_uniformchain_value_char();
		}else
		{
			$this->UniformChains = new soap_array_of_uniformchain_of_chains();
		}

		while ($uniform_chain = $chain_list->get_next(false, true))
		{
			$temp  = new soap_uniformchain();
			$temp->load_from_db($uniform_chain->chain->chain_id->get_value());
			$this->UniformChains->add($temp);
		}
	}
}
?>
